#include <stdio.h>

typedef int node;
#define key(A) (A)

void merge_2way(node* , node* , int , node* , int );

int main() {
  node v[] = {6, 7, 8, 9};
  node w[] = {1, 2, 3};
  node out[7];
  merge_2way(out, v, 4, w, 3);
  //int i; for (i = 0; i < 7; i++) printf("%i ", out[i]);
  return 0; 
}

void merge_2way(node c[], node a[], int n, node b[], int m)
{
  int i, j , k;
  for (i = 0, j = 0, k = 0; k < n+m; k++) {
    if (i == n) {
      c[k] = b[j++];
      continue;
    }
    if (j == m) {
      c[k] = a[i++];
      continue;
    }    
    c[k] = (key(a[i]) < key(b[j])) ? a[i++] : b[j++];
  }         
}

